package com.syb.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.syb.dao.ResourcesDao;
import com.syb.entity.function.SysResource;
import com.syb.service.ResourceService;
import com.syb.util.PageResults;

@Service
public class ResourceServiceImpl implements ResourceService {

	@Autowired
	private ResourcesDao resourceDao;
	
	@Override
	public PageResults<SysResource> findSysResourcesList(PageResults<SysResource> page) throws Exception {
		PageResults<SysResource> pageList = new PageResults<SysResource>();
		List<SysResource> resourceList  = new ArrayList<SysResource>();
		int count = 0 ;
		try{
			resourceList = resourceDao.findResourcesList(page);
		}catch(Exception e){
			throw new Exception(e.getMessage());
		}
		try{
			count = resourceDao.findResourcesCount(page);
		}catch(Exception e){
			throw new Exception(e.getMessage());
		}
		pageList.setResults(resourceList);
		pageList.setTotalCount(count);
		pageList.setPageNo((page.getCurrentPage()/page.getPageSize())+1);
		return pageList;
	}

}
